﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aldebaran.Proxies;

namespace grounding.nao.sensors
{
    public class BatterySensor : ISensor
    {
        private SentinelProxy sentinelProxy;
        private string name;

        public string Name { get { return name; } }
        public string Type { get { return "battery"; } }

        /// <summary>
        /// Assumes proxies are connected to robot.
        /// </summary>
        /// <param name="sentinelProxy">established SentinelProxy</param>
        public BatterySensor(SentinelProxy sentinelProxy, string name)
        {
            this.sentinelProxy = sentinelProxy;
            this.name = name;
        }

        /// <summary>
        /// Polls battery percentage.
        /// </summary>
        /// <returns>A BatterySensorFrame with the current battery percentage.</returns>
        public ISensorFrame GetSensorFrame() { return GetSensorFrame(x => x); }
        /// <summary>
        /// Polls battery percentage.
        /// </summary>
        /// <returns>A BatterySensorFrame with the current battery percentage.</returns>
        public ISensorFrame GetSensorFrame(Func<IEnumerable<double>, IEnumerable<double>> transformer)
        {
            int currentLevel = sentinelProxy.getBatteryLevel();
            double[] data = { currentLevel / 5.0f };

            return new BatterySensorFrame(this, transformer(data).ToArray());
        }
    }
}
